1
단일 프롬프트를 넘어선 복잡한 워크플로우로의 전환
AI010Lesson 4
00:00

"메가-프롬프트" 시대의 종말

초기 LLM 개발 단계에서 사용자들은 종종 모든 지시사항, 제약 조건, 데이터 포인트를 하나의 거대한 프롬프트에 "압축"하려 했습니다. 직관적으로는 타당해 보이지만, 이 접근 방식은 과적합고비용 토큰 사용과 함께, 디버깅이 거의 불가능한 '블랙박스'를 만들어냅니다.

업계는 프롬프트 체이닝이라는 모듈화된 접근 방식으로, 일반적인 전문가가 아니라 각각 특정 업무에 특화된 작업자들로 구성된 시스템처럼 작동하도록 합니다.

왜 프롬프트를 연결해야 할까요?

  • 신뢰성:복잡한 작업을 관리 가능한 하위 작업으로 분해하면 환각률이 크게 감소합니다.
  • 통합성:외부 도구(예: 내부의 JSON 데이터베이스 또는 API)로부터 데이터를 워크플로우 중간에 동적으로 주입할 수 있게 해줍니다.
  • 비용 효율성:각 단계에 필요한 최소한의 컨텍스트만 전송하기 때문에 토큰을 절약할 수 있습니다.
참고 원칙: 작업 분해
한 프롬프트는 하나의 구체적인 업무만을 처리해야 합니다. 만약 한 번의 프롬프트 지시문에서 세 번 이상의 '그리고 다음에' 문장을 사용하고 있다면, 이를 별도의 호출로 나누어 체이닝하는 시점입니다.
pipeline.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute pipeline.
>
Knowledge Check
Why is "Dynamic Context Loading" (fetching data mid-workflow) preferred over putting all possible information into a single system prompt?
It makes the model run faster on local hardware.
It prevents model confusion and reduces token costs by only providing necessary data.
It allows the model to ignore the system instructions.
Challenge: Designing a Safe Support Bot
Apply prompt chaining principles to a real-world scenario.
You are building a tech support bot. A user asks for the manual of a "X-2000 Laptop."

Your task is to define the logical sequence of prompts needed to verify the product exists in your database and ensure the final output doesn't contain prohibited safety violations.
Step 1
What should the first two actions in your pipeline be immediately after receiving the user's message?
Solution:
1. Input Moderation: Check if the prompt contains malicious injection attempts. Evaluate as $ (N/Y) $.
2. Entity Extraction: Use a specialized prompt to extract the product name ("X-2000 Laptop") from the raw text.
Step 2
Once the entity is extracted, how do you generate the final safe response?
Solution:
1. Database Lookup: Query the internal DB for "X-2000 Laptop" manual data.
2. Response Generation: Pass the user query AND the retrieved DB data to the LLM to draft an answer.
3. Output Moderation: Run a final check on the generated text to ensure no safety policies were violated before sending it to the user.